import {reqGoodsDetailInfo} from "@/api";

const state = {
    goodsDetailInfo:{}
}
const mutations = {
    RECEIVE_GOODSDETAILINFO(state,goodsDetailInfo){
        state.goodsDetailInfo = goodsDetailInfo
    }
}
const actions = {
    async getGoodsDetail({commit},skuId){
        try {
        const result = await reqGoodsDetailInfo(skuId);
        if (result && result.code === 200){
        commit('RECEIVE_GOODSDETAILINFO',result.data);
            console.log(result.data)
        }
        }catch (error){
            alert("获取详情信息失败")
        }
    }
}
const getters = {
    categoryView(state) {
        return state.goodsDetailInfo.categoryView || {};
    },
    skuInfo(state) {
        return state.goodsDetailInfo.skuInfo || {};
    },
    spuSaleAttrList(state) {
        return state.goodsDetailInfo.spuSaleAttrList || {};
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
}